<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <link rel="stylesheet" href="../css/taxbill.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="title">
        <em></em>
        <h3>发票管理（服务商）</h3>
    </div>
    
        <form class="layui-form layui-form-padding" action="">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="tel" name="sellerName" placeholder="请输入客户名称" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit="" lay-filter="searchBtn">查询</button>
                <button type="reset" class="layui-btn layui-btn-primary">清空</button>
            </div>
        </div>
    </form>

    <div class="layuimini-main">



        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title shaixuan_btn_list" style="margin-bottom: 30px; border: none;">
                <li class="layui-this" data-state="-1">全部</li>
                <li data-state="0">待审核</li>
                <li data-state="1">已完成</li>
                <li data-state="2">驳回</li>
            </ul>
            
            <a lay-filter="exportAll" lay-submit="" class="layui-btn">导出全部</a>
            <a lay-filter="exportNo" lay-submit="" class="layui-btn">导出未完成</a>
            <a lay-filter="exportYes" lay-submit="" class="layui-btn">导出已完成</a>
             <a lay-filter="invoiceAlert" lay-submit="" class="layui-btn">发票预警</a>
        </div>


        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
    <script type="text/html" id="currentTableBar">
        {{#  if(d.status == '0'){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">修改状态</a>

        {{#  }else if(d.status == '1'){ }}
        <span style="color: #3aadff;">已完成</span>&nbsp;&nbsp;&nbsp;
		<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="expedit">修改单号</a>

        {{#  }else if(d.status == '2'){ }}
        <span style="color: red;">驳回</span>
        {{#  } }}
		
		<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="view">查看</a>
		

    </script>
    
                <script type="text/html" id="billType">
                {{#  if(d.billTypeId == '0'){ }}
                <span style="color: #1aa094">专票</span>
                {{#  }else if(d.billTypeId == '1'){ }}
                <span style="color: #3aadff">普票</span>
                {{#  } }}
            </script>

</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    var this_ = '',tableIns = '';
    layui.use(['form', 'table','jquery','tfApi'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            $ = layui.jquery,
            this_ = $,
            API = layui.tfApi;

        tableIns = table.render({
            elem: '#currentTableId',
            url: API.CURL + '/service/qryServiceInvoice',
            cellMinWidth: 60,
            method: "POST",
            contentType: 'application/json',
            xhrFields: {withCredentials: true},crossDomain: true,
            request:{
                pageName: "page",
                limitName : "pageSize"
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list, //解析数据列表
                };
            },
            cols: [[
                {field: 'billCode', title: 'ID',hide:true},
                {field: 'billCode', title: '发票编号'},
                {field: 'username', title: '收票人信息',width:150,templet:function(d){
                    return '<div> 收件人姓名：'+d.rname+'</div><br/><div>收件人手机号:' +d.mobile+'</div><br/><div>收件人地址:' +d.address+'</div>';
                }},
                {field: 'sellerName', title: '发票信息',width:300,templet:function(d){
                	d.taxPayerCode=d.taxPayerCode==undefined?"":d.taxPayerCode;
                	return '<div> 名称：'+d.sellerCompanyName+'</div><br/><div> 地址：'+d.serviceAddress+'</div><br/><div> 税号：'+d.taxPayerCode+'</div><br/>'+
                	'<div> 账户：'+d.sellerBankAccount+'</div><br/><div>开户行:' +d.sellerBank+'</div>';
                }},
                
                {field: 'taxableTotal', title: '发票内容',width:300,templet:function(d){
                    return '<div> 发票金额：'+formatMoney(d.taxableTotal)+'</div><br/><div>发票类目:' +d.billContent+'</div><br/><div>发票类型:' +getBillType(d.billTypeId)+'</div>';
                }},
                
                {field: 'billNumber', title: '发票号'},
				{field: 'expressCode', title: '快递单号'},
                {field: 'username', title: '销售方',templet:function(d){
                    return '<div> 名称：'+d.serviceName+'</div><br/><div>纳税人识别码:' +d.enterpriseCode+'</div>';
                }},
                {field: 'createTime', title: '申请时间'},
                {field: 'status', title: '操作',toolbar: '#currentTableBar', align: "center"},
            ]],
            id: 'invoiceReload',
            page: true,
            //skin: 'line'
        });
        //监听提交
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑发票状态',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/modify.html',
                    success: function (layero, index) {
                        var frameId = $(layero).find('iframe').attr("id");
                        //找到子页面的document对象
                        var document = window.frames[frameId].document;
                        //根据id找到子页面中相应的元素并赋值
                        //$(document).find("input[name='modifyId']").val(data.id);
                        $(document).find("input[name='billCode']").val(data.billCode);
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }else if(obj.event === 'expedit'){
			var index = layer.open({
                    title: '修改快递单号',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/expedit.html',
                    success: function (layero, index) {
                        var frameId = $(layero).find('iframe').attr("id");
                        //找到子页面的document对象
                        var document = window.frames[frameId].document;
                        //根据id找到子页面中相应的元素并赋值
                        //$(document).find("input[name='modifyId']").val(data.id);
                        $(document).find("input[name='billCode']").val(data.billCode);
						$(document).find("input[name='expressCode']").val(data.expressCode);
                        $(document).find("input[name='billNumber']").val(data.billNumber);
                    }
                });
			}else if(obj.event === 'view'){
			var index = layer.open({
                    title: '查看发票信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/view.html',
                    success: function (layero, index) {
                        var frameId = $(layero).find('iframe').attr("id");
                        //找到子页面的document对象
                        var document = window.frames[frameId].document;
                        //根据id找到子页面中相应的元素并赋值
                        //$(document).find("input[name='modifyId']").val(data.id);
						document.getElementById('billCode').innerText=data.billCode;
						document.getElementById('billContent').innerText=data.billContent;
						document.getElementById('taxableTotal').innerText=data.taxableTotal;
						document.getElementById('billNumber').innerText=data.billNumber;
						document.getElementById('expressCode').innerText=data.expressCode;
						document.getElementById('sellerCompanyName').innerText=data.sellerCompanyName;
						document.getElementById('taxPayerCode').innerText=data.taxPayerCode;
						document.getElementById('serviceName').innerText=data.serviceName;
						document.getElementById('enterpriseCode').innerText=data.enterpriseCode;
						document.getElementById('rname').innerText=data.rname;
						document.getElementById('mobile').innerText=data.mobile;
						document.getElementById('address').innerText=data.address;
						document.getElementById('sellerName').innerText=data.sellerName;
						document.getElementById('createTime').innerText=data.createTime;
                    }
                });
			}
        });
        $("#bigImg").click(function(){
            var t = $(this).find("img");
            console.log(t)
        });

        function reloadFun(s){
            var _data = {status: s.toString()};
            //执行重载
            table.reload('invoiceReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: _data
            }, 'data');
        }
        
        //监听提交
        form.on('submit(searchBtn)', function (data) {

            var sellerName = $("input[name='sellerName']").val();
            let query_y = {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , done: function (res, curr, count) {
                    //完成后重置where，解决下一次请求携带旧数据
                    //  this.where = {};
                }
            };

            query_y.where = {
                "sellerName" : sellerName
            };
            tableIns.reload(query_y);
            return false;

        });

        $('.shaixuan_btn_list li').on('click', function(){
            $(".shaixuan_btn_list li").removeClass('layui-this');
            $(this).addClass("layui-this");
            var state = $(this).data('state');
            //active['reload'] ? active['reload'].call(this) : '';
            reloadFun(state);
            console.log("state=="+state);
        });
        
        form.on('submit(exportAll)', function(){
        	location.href= API.CURL + '/service/export?status=-1';
  		  //alert("导出");
  	  });
        form.on('submit(exportNo)', function(){
        	location.href= API.CURL + '/service/export?status=0';
  		  //alert("导出");
  	  });
        form.on('submit(exportYes)', function(){
        	location.href= API.CURL + '/service/export?status=1';
  		  //alert("导出");
  	  });
        
        
        form.on('submit(invoiceAlert)', function(){
        	var index = layer.open({
                title: '发票预警',
                type: 2,
                shade: 0.2,
                maxmin:true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: '../page/table/addinvoiceAlert.html',
                end:function(){
                    location.reload();
                }
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
  	  });

    });
    function show_img(t) {
        console.log("----->",t)
        var t = this_(t).find("img");
        //页面层
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
             area: ['80%', '80%'], //宽高
            shadeClose: true, //开启遮罩关闭
            end: function (index, layero) {
                return false;
            },
            content: '<div style="text-align:center"><img src="' + this_(t).attr('src') + '" /></div>'
        });
    }
    
    function money(d){
    	let number = d.taxableTotal;
    	number = number.toString().replace(/\,/g, "");
    	if(isNaN(number) || number == "")return "";
    	number = Math.round(number * 100) / 100;
    	    if (number < 0)
    	        return '-' + outputdollars(Math.floor(Math.abs(number) - 0) + '') + outputcents(Math.abs(number) - 0);
    	    else
    	        return outputdollars(Math.floor(number - 0) + '') + outputcents(number - 0);
    	} 
    	//格式化金额
    	function outputdollars(number) {
    	    if (number.length <= 3)
    	        return (number == '' ? '0' : number);
    	    else {
    	        var mod = number.length % 3;
    	        var output = (mod == 0 ? '' : (number.substring(0, mod)));
    	        for (i = 0; i < Math.floor(number.length / 3); i++) {
    	            if ((mod == 0) && (i == 0))
    	                output += number.substring(mod + 3 * i, mod + 3 * i + 3);
    	            else
    	                output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
    	        }
    	        return (output);
    	    }
    	}
    	function outputcents(amount) {
    	    amount = Math.round(((amount) - Math.floor(amount)) * 100);
    	    return (amount < 10 ? '.0' + amount : '.' + amount);
    	}
    	
        function formatMoney(str) {
            if (!str) str = '0.00';
            let ret = Math.round(parseFloat(str) * 100) / 100;
            let decimal = ret.toString().split('.');
            if (decimal.length === 1) {
                return ret.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
                    + '.00';
            };
            if (decimal.length > 1) {
                decimal[0] = decimal[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                if (decimal[1].length < 2) {
                    decimal[1] += '0';
                    return decimal.join(".");
                }
                return decimal.join(".");
            };
            return ret;
        }
        
        function getBillType(type){
        	if(type == '0'){
        		return '专票';
        	}else if(type == '1'){
        		return '普票';
        	}
        }
    	
</script>

</body>
</html>